package com.xjtu.platform.security.impl;

import com.xjtu.platform.security.dto.AdminLoginDto;
import com.xjtu.platform.security.dto.LoginDto;
import com.xjtu.platform.security.LoginService;
import com.xjtu.platform.security.dao.LoginDao;
import com.xjtu.platform.security.dto.NewPwdDto;
import com.xjtu.platform.security.entitiy.Info;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
@Transactional
public class LoginServiceImpl implements LoginService {

    @Resource
    private LoginDao loginDao;

    @Override
    public boolean checkLogin(LoginDto loginDto) {
        int count = loginDao.checkLogin(loginDto);
        return count > 0;
    }


    @Override
    public String getReaderId(String readerCode) {
        String reader_id = loginDao.getReaderId(readerCode);
        return reader_id;
    }

    @Override
    public boolean updatePwd(NewPwdDto newPwdDto, String readerId) {
        try {
            loginDao.updatePwd(newPwdDto, readerId);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public Info getInfo(String readerId) {
        return loginDao.getInfo(readerId);
    }

    @Override
    public boolean checkAdminLogin(AdminLoginDto adminLoginDto) {
        int count = loginDao.checkAdminLogin(adminLoginDto);
        return count > 0;
    }

    @Override
    public String getAdminId(String admin_code) {
        String admin_id = loginDao.getAdminId(admin_code);
        return admin_id;
    }

}
